import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false, //登录状态
		token:"",     // token
		email:"",//微信登录 唯一标识
		relevanceUserID:-1,  // 是否已经关联小程序（保存userID）
		createProjectData:{}, // 记录每一步创建的数据 // 以及需要修改的数据
		curEditProjectID:"" //当前需要修改的项目ID
	},
	mutations: {
		// 普通用户登录退出
		login(state, data) {
			state.hasLogin = true;
			state.token = data.token;
			state.email = data.email;
			state.relevanceUserID = data.relevanceUserID;
		},
		logout(state) {
			state.hasLogin = false;
			state.token = "";
			state.email = "";
			state.relevanceUserID = -1;
		},
		createProject(state,data){
			let curData;
			if(data.val === -1){  //取消选中
				curData = Object.assign({},state.createProjectData,{[data.key]:""})
				state.createProjectData = curData;
			} else {
				curData = Object.assign({},state.createProjectData,{[data.key]:data.val});
				state.createProjectData = curData;
			}
		},
		setEditProjectID(state,id){
			state.curEditProjectID = id;
		}
		
		
	},
	actions: {
	
	}
	// getters:{
	// 	createProjectData(state){
	// 		return state.createProjectData;
	// 	}
	// }
})

export default store
